<?
if(!admin_isadmin())die();

// wiki
// diff


//__ METHOD ____________________________________________
    $_action=$_GET['_action'];

    $_difffile=$_GET['difffile'];

    if ($_action=="diff"){
	echo"
	<font size=6><b>diff in file $_difffile </b></font><br />\n

	<table border='2'>

	<tr>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>filename</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>date update</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>author</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>view</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>resume</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>delete</b></font></td>
	</tr>
	";
	if ($lockdir=@opendir("datas/applications/".apptitle($appname)."/history")) {
	    $di=0;
	    while(($listfile[$di++]=readdir($lockdir))!=false);
	    for ($di=0;$di<count($listfile)-1;$di++)
		for($di1=$di;$di1<count($listfile)-1;$di1++)
		    if (filemtime("datas/applications/".apptitle($appname)."/history/$listfile[$di]")<filemtime("datas/applications/".apptitle($appname)."/history/$listfile[$di1]")){
			$tmp=$listfile[$di];
			$listfile[$di]=$listfile[$di1];
			$listfile[$di1]=$tmp;
		    }
	    for($di=0;$di<count($listfile)-1;$di++){
		$versionfile=$listfile[$di];
		if (strncmp($_difffile.".",$versionfile,strlen($_difffile)+1)==0){
		    echo "<tr>";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'><b>$versionfile</b></td>\n";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'>".date("j F Y g:i a",filemtime("datas/applications/".apptitle($appname)."/history/$versionfile"))."</font></td>\n";
		    $ta=file("datas/applications/".apptitle($appname)."/history/$versionfile");
		    $author=$ta[0];
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'>$author</font></td>\n";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'><a href=\"index.php?appname=$appname&action=admin&difffile=$_difffile&versionfile=$versionfile&_action=diff&_subaction=view\">view</a></font></td>\n";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'><a href=\"index.php?appname=$appname&action=admin&difffile=$_difffile&versionfile=$versionfile&_action=diff&_subaction=resume\">resume</a></font></td>\n";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'><a href=\"index.php?appname=$appname&action=admin&difffile=$_difffile&versionfile=$versionfile&_action=diff&_subaction=delete\">delete</a></font></td>\n";
		    echo "</tr>\n";
		}

	    }
	closedir($lockdir);
	}
	echo "</table>\n";
	echo "</font>\n";
	echo "<hr />\n";

    }

    $_subaction=$_GET['_subaction'];
    $_versionfile=$_GET['versionfile'];

    if ($_subaction=="view"){
    	admin_writelog("vwiki:view page");

	echo"
	<table border='2' width='100%'>
	<tr>
	<td style='color: rgb(255, 255, 255); background-color: rgb(0, 204, 51);'><font size='2'><b>Preview of $_versionfile</b></font></td>
	</table>
	";
        $ta=file("datas/applications/".apptitle($appname)."/history/$_versionfile");
	for($r=1;$r<count($ta);$r++)
	    echo(rawurldecode($ta[$r]));
	echo"
	<table border='2' width='100%'>
	<tr>
	<td style='color: rgb(255, 255, 255); background-color: rgb(0,204, 51);'><font size='2'><b>End of preview of $_versionfile</b></font></td>
	</table>
	";

    }

    if ($_subaction=="resume"){
	admin_writelog("vwiki:resume page");

	$rta="";
        $ta=file("datas/applications/".apptitle($appname)."/history/$_versionfile");
	for($r=1;$r<count($ta);$r++){
	    $rta=$rta.$ta[$r];
	}
	echo"
	<font size=6><b>do you want resume $_versionfile ?</b></font>
	<form name=\"form1\" action=\"index.php?appname=$appname&page=$_difffile\" method=\"post\" enctype=\"multipart/form-data\" >\n
	<input type=\"Hidden\" name=\"ta\" value=\"$rta\" />\n
	<input type=\"submit\" value=\"click me to resume the page\">
	</form><hr />
	";

    }

    if ($_subaction=="delete"){
	admin_writelog("vwiki:delete page");
        unlink("datas/applications/".apptitle($appname)."/history/$_versionfile");
	echo "file $_versionfile deleted <a href=\"index.php?appname=$appname&action=admin&difffile=$_difffile&_action=diff\">refresh</a></font>";

    }

?>
